<style>
.Wdate{
	height:30px;
	width:250px;
}
</style>
<div class="row">
	<div class="col-lg-12">
		<h1 class="page-header">更改服务器状态</h1>
	</div>
	<!-- /.col-lg-12 -->
</div>
<div class="well">
	<button class="btn btn-primary" type="button" onclick="P.setAllStatus(1);">设为全部维护</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<button class="btn btn-danger" type="button" onclick="P.setAllStatus(0);">取消全部维护</button>
</div>
<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-body">
				<table width="100%" class="table table-striped table-bordered table-hover" id="chatTable">
					<thead>
					<tr>
						<th>服务器</th>
						<th>状态</th>
						<th>is_new</th>
						<th>default_enter</th>
						<th>维护公告</th>
					</tr>
					</thead>
					<tbody>
					<?php
					foreach($serverList as $k=>$v):
						$status = ($v['status']==1) ? '<span style="color:red">维护状态</span>' : '正常游戏';
					?>
						<tr>
							<td><?=$v['area_name']."|".$v['name']?></td>
							<td>
								<?="status=".$v['status']." "?>
								<?=$status?>
								<?php if($v['status']==1):?>
									<button class="btn btn-primary btn-xs" type="button" onclick="P.alterFieldValue(<?=$v['id']?>, 'status', 0);">取消维护</button>
								<?php else: ?>
									<button class="btn btn-danger btn-xs" type="button" onclick="P.alterFieldValue(<?=$v['id']?>, 'status', 1);">设为维护</button>
								<?php endif;?>
							</td>
							<td>
								<?=$v['is_new']?>
								<?php
								$new2 = ($v['is_new']==0) ? 1 : 0;
								?>
								<button class="btn btn-info btn-xs" type="button" onclick="P.alterFieldValue(<?=$v['id']?>, 'is_new', <?=$new2?>);">更改</button>
							</td>
							<td>
								<?=$v['default_enter']?>
								<?php
								if($v['default_enter']==0):
								?>
								<button class="btn btn-info btn-xs" type="button" onclick="P.alterFieldValue(<?=$v['id']?>, 'default_enter', 1);">默认</button>
								<?php endif;?>
							</td>
							<td onclick="P.changeMaintainNotice();">
								<div id="text_notice_<?=$v['id']?>" class="notice1">
									<button class="btn btn-danger btn-xs" type="button" onclick="P.showAlterMaintainNotice(<?=$v['id']?>);">更改</button>
									<?=$v['maintain_notice']?>
								</div>
								<div id="notice_<?=$v['id']?>" style="display:none;" class="notice2">
									<textarea class="form-control" rows="2" cols="70" id="notice_val_<?=$v['id']?>"><?=$v['maintain_notice']?></textarea>
									<button class="btn btn-success btn-xs" type="button" onclick="P.alterFieldValue(<?=$v['id']?>, 'maintain_notice');">确定</button>
								</div>
							</td>
						</tr>
					<?php endforeach;?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>

<script>
	var P = {};
	/**
	 * 更改字段值
	 * @param id
	 * @param field
	 * @param value
	 */
	P.alterFieldValue = function (id, field, value) {
		if(field=='maintain_notice') {
			value = $('#notice_val_'+id).val();
		}
		$.post('/admin/ajaxAlterServerListField', {"id":id, "field":field, "value":value}, function(o){
			alertOk('更改成功', flushPage);
		});
	};
	/**
	 * 显示更改公告area
	 * @param id
	 */
	P.showAlterMaintainNotice = function(id){
		$('.notice2').hide();
		$('.notice1').show();
		$('#text_notice_'+id).hide();
		$('#notice_'+id).show();
	};
	/**
	 * 更改所有服状态
	 * @param status
	 */
	P.setAllStatus = function (status){
		$.post('/admin/ajaxAlterServerListField', {"id":0,"field":"all_status", "value":status}, function(o){
			alertOk('更改成功', flushPage);
		});
	};
	/**
	 * 刷新页面
	 */
	function flushPage(){
		location.reload();
	}

$(document).ready(function(){
	$('#chatTable').DataTable({
		"pageLength": 10,
		"order": [[ 0, "asc" ]]
	});
});
</script>